<script setup lang="ts">
import { useI18n } from '@/hooks/web/useI18n'
import { ref, reactive } from 'vue'
import { Form, FormSchema } from '@/components/Form'
import { useValidator } from '@/hooks/web/useValidator'
import { getDictOneApi } from '@/api/common'
import { useForm } from '@/hooks/web/useForm'

const { required } = useValidator()

const { t } = useI18n()

const { formRegister, formMethods } = useForm()
const { getElFormExpose } = formMethods
const { getFormData } = formMethods

const schema = reactive<FormSchema[]>([
  {
    field: 'auditState',
    label: '结果',
    component: 'Select',
    formItemProps: {
      rules: [required()]
    },
    componentProps: {
      options: [
        {
          label: '上架',
          value: 'Online'
        },
        {
          label: '下架',
          value: 'Offline'
        }
      ]
    }
  },
  {
    field: 'auditRemark',
    label: '审批意见',
    component: 'Input'
  }
])

const formSubmit = async () => {
  const elForm = await getElFormExpose()
  const valid = await elForm?.validate().catch((err) => {
    console.log(err)
  })
  if (valid) {
    const formData = await getFormData()
    return formData
  }
}

defineExpose({
  formAudit: formSubmit
})
</script>

<template>
  <Form :schema="schema" @register="formRegister" />
</template>
